﻿using UnityEngine;
using System.Collections;

public class TestBattleStart : MonoBehaviour {

	public bool isPvp;
	public bool isViewerStart;

	void OnPress(bool isDown)
	{
		if(isDown) {
			if(isViewerStart) {
				GameObject go = new GameObject();
				go.name="CharacterViewer";
				go.AddComponent<CharacterViewer>();
			}
			else {
				Debug.Log("TestBattleStart click  pvp="+isPvp);
				NetworkManager.Instance.C2S_LOGIN(AuthPlatformID.None, BattleManager.Instance.battleTestId, string.Empty, ResponseLogin, null);
			}
		}
	}

	private void ResponseLogin(ResponseModel<UserModel> result)
	{
		if (result.ecode != 0)
			return;
		
		Debug.Log(result.data.account);
		UserData.Instance.userModel = result.data;
		//BattleManager.Instance.bTestStartBattle=true;
		if(isPvp) {
			NetworkManager.Instance.C2S_QUICK_START(UserData.Instance.userModel.choiceMembers.ToArray(), null, (responseData) => {
				if (responseData.ecode != 0)
				{
					Debug.Log("quick_start response error");
					return;
				}
				
				// 빠른 PVP 상대의 UserModel 설정
				UserData.Instance.quickPVPUserModel = responseData.data;
				BattleManager.Instance.InitGame(isPvp);
			});
		}
		else
			BattleManager.Instance.InitGame(isPvp);
	}
}
